define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/index' + location.search,
                    add_url: 'order/add',
                    // edit_url: 'order/edit',
                    // del_url: 'order/del',
                    multi_url: 'order/multi',
                    import_url: 'order/import',
                    importtow_url:'order/importtwo',
                    table: 'order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {
                            field: 'is_up',
                            title: __('是否更新'),
                            searchList: {"1":__('否'),"2":__('是')},
                            formatter: Table.api.formatter.toggle,
                            yes: 2,
                            no: 1
                        },
                        {field: 'packages.card_type', title: __('版本'), searchList: {"1":__('充值版'),"2":__('激活版')}, formatter: Table.api.formatter.status},
                        {field: 'packages.pay_channel', title: __('渠道'), searchList: {"1":__('微信/支付宝'),"2":__('快递处')}, formatter: Table.api.formatter.status},
                        {field: 'order_id', title: __('Order_id'), operate: 'LIKE'},
                        {field: 'phone', title: __('Phone'), operate: 'LIKE'},
                        {field: 'platform_type', title: __('Platform_type'), searchList: {"1":__('Platform_type 1'),"2":__('Platform_type 2'),"3":__('Platform_type 3'),"4":__('Platform_type 4'),"5":__('Platform_type 5'),"6":__('Platform_type 6'),"7":__('Platform_type 7')}, formatter: Table.api.formatter.status},
                        {field: 'image', title: __('上传截图'), events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false},
                        {field: 'audit_upload_time', title: __('上传时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'is_hexiao', title: __('核销状态'), searchList: {1:__('未核销'),2:__('已核销'),3:__('已逾期')}, formatter: Table.api.formatter.status},
                        {field: 'user.username', title: __('代理名称'), operate: 'LIKE'},
                        // {
                        //     field: 'audit_status',
                        //     title: __('充值处理'),
                        //     searchList: {"0":__('未处理'),"1":__('已处理 ')},
                        //     formatter: Table.api.formatter.status
                        // },
                        {
                            field: 'order_status',
                            title: __('Order_status'),
                            searchList: {"0":__('Order_status 0'),"1":__('Order_status 1'),"2":__('Order_status 2'),"3":__('Order_status 3'),"4":__('Order_status 4'),"5":__('Order_status 5'),"6":__('Order_status 6')},
                            formatter: Table.api.formatter.status
                        },
                        {
                            field: 'recover_status',
                            title: __('佣金追回'),
                            searchList: {"1":__('正常单'),"2":__('已追回')},
                            formatter: Table.api.formatter.status
                        },
                        {
                            field: 'rebate_recover_msg',
                            title: __('佣金原因'),
                            operate: 'LIKE'
                        },
                        {field: 'rebate_recover_money', title: __('追回金额'), operate: 'LIKE'},

                        {field: 'recover_time', title: __('追回时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},

                        {field: 'shipping_contact', title: __('Shipping_contact'), operate: 'LIKE'},
                        {field: 'shipping_phone', title: __('Shipping_phone'), operate: 'LIKE'},
                        {field: 'shipping_idcard', title: __('Shipping_idcard'), operate: 'LIKE'},
                        {field: 'shipping_province', title: __('Shipping_province'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'shipping_city', title: __('Shipping_city'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'shipping_area', title: __('Shipping_area'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'shipping_address', title: __('Shipping_address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'is_callback', title: __('Is_callback'), searchList: {"1":__('Is_callback 1'),"2":__('Is_callback 2')}, formatter: Table.api.formatter.normal},
                        // {field: 'user_rebate', title: __('User_rebate'), operate:'BETWEEN'},
                        {field: 'shipping_company_name', title: __('Shipping_company_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'shipping_no', title: __('Shipping_no'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'is_recharged', title: __('Is_recharged'), searchList: {"0":__('Is_recharged 0'),"1":__('Is_recharged 1')}, formatter: Table.api.formatter.normal},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'callback_time', title: __('Callback_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},

                        // {field: 'user.mobile', title: __('User.mobile'), operate: 'LIKE'},
                        {field: 'packages.name', title: __('Packages.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {
                            field: 'gys',
                            title: __('供应商'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'detail',
                                    text: __('审核'),
                                    icon: 'fa fa-list',
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    url: 'order/audit',
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        // if(Config.ids == 4){
                                        //     return false;
                                        // }
                                        if(row.packages.card_type==1){
                                            if(row.audit_status==1 || row.audit_status==2 || row.audit_status==3){
                                                return true;
                                            }else{
                                                return false;
                                            }
                                        }else{
                                            return false;
                                        }

                                    },
                                },
                                {
                                    name: 'detail',
                                    text: __('修改订单'),
                                    icon: 'fa fa-list',
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    url: 'orderagency/edit',
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if(Config.quanxian.ids==6){
                                            return false;
                                        }else{
                                            return true;
                                        }
                                    },
                                },
                                {
                                    name: 'detail',
                                    text: __('详情'),
                                    icon: 'fa fa-list',
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    url: 'order/orderinfo',
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if(Config.quanxian.ids==6){
                                            return false;
                                        }else{
                                            if(row.platform_type==1){
                                                return true;
                                            }else{
                                                return false;
                                            }
                                        }

                                    },
                                },
                                {
                                    name: 'detail',
                                    text: __('充值处理'),
                                    icon: 'fa fa-list',
                                    classname: 'btn btn-xs btn-danger btn-magic btn-dialog',
                                    url: 'order/orderchuli',
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if(row.packages.card_type ==2){
                                                if(row.packages.pay_channel ==1){
                                                    if(!row.image && row.audit_status > 0){
                                                        return true;
                                                    }else{
                                                        return false;
                                                    }
                                                }else{
                                                    if(row.twoimage && row.phone && !row.image){
                                                        return true;
                                                    }else{
                                                        return false;
                                                    }
                                                }
                                        }else{
                                            return false;
                                        }

                                    },
                                },

                                {
                                    name: 'detail',
                                    text: __('已充值'),
                                    icon: 'fa fa-magic',
                                    classname: 'btn btn-xs btn-success btn-magic btn-dialog',
                                    url: 'order/orderchuli',
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if(row.packages.card_type ==2){
                                            if(row.packages.pay_channel ==1){
                                                if(row.phone && row.image){
                                                    return true;
                                                }else{
                                                    return false;
                                                }
                                            }else{
                                                if(row.twoimage && row.phone && row.image){
                                                    return true;
                                                }else{
                                                    return false;
                                                }
                                            }
                                        }else{
                                            return false;
                                        }
                                    },
                                },
                                {
                                    name: 'detail',
                                    text: __('追回佣金'),
                                    icon: 'fa fa-list',
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    url: 'order/recover',
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if(Config.quanxian.ids==6){
                                            return false;
                                        }else{
                                            return true;
                                        }
                                    },
                                },
                                {
                                    name: 'detail',
                                    text: __('核销'),
                                    icon: 'fa fa-list',
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    url: 'order/hexiao',
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if(Config.quanxian.ids==6){
                                            return false;
                                        }else{
                                            if(row.is_hexiao==1){
                                                return true;
                                            }else{
                                                return false;
                                            }
                                        }
                                    },
                                },
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        audit: function () {
            Controller.api.bindevent();
        },
        recover:function (){
            Controller.api.bindevent();
        },
        orderinfo:function (){
            Controller.api.bindevent();
        },
        orderchuli:function (){
            Controller.api.bindevent();
        },
        hexiao:function (){
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
